package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.model.Problem;
import org.springframework.data.jpa.repository.Query;


public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    @Query(nativeQuery = true , value = "SELECT * FROM tb_problem pro , tb_pl pl WHERE " +
            " pro.id = pl.problemid  AND pl.labelid=? ORDER BY pro.replytime DESC " )
    Page<Problem> newList(String labelId , Pageable pageable);

    @Query(nativeQuery = true , value = "SELECT * FROM tb_problem pro , tb_pl pl WHERE " +
            " pro.id = pl.problemid AND pl.labelid=? ORDER BY pro.reply DESC ")
    Page<Problem> hotList(String labelId , Pageable pageable);

    @Query(nativeQuery = true , value = "SELECT pro.* FROM tb_problem pro , tb_pl pl WHERE " +
            " pro.id = pl.problemid AND pl.labelid =? AND pro.reply = 0 ORDER BY pro.createtime DESC ")
    Page<Problem> waitList(String labelId , Pageable pageable);


}
